package pers.crayon.baseprogram.convert;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import pers.crayon.baseprogram.model.dto.CarDto;
import pers.crayon.baseprogram.model.entity.Car;

/**
 * 使用mapStruct自带的@Mapper
 * mappings映射多个属性
 * mappings内使用mapping映射单个属性，
 *
 * @author wangzg13
 * @since 2022/9/6
 */
@Mapper(componentModel = "spring")//,uses = StringMapper.class
public interface CarMapper {

    /**
     * 用来调用实例 实际开发中可使用注入Spring  不写
     *
     * @Mapper(componentModel = "spring")
     */
    //CarMapper INSTANCE = Mappers.getMapper(CarMapper.class);
    //expression = "java(new BigDecimal(car.getSellingPrice()).setScale(2,BigDecimal.ROUND_DOWN))"
    @Mappings({@Mapping(source = "numberOfSeats", target = "seatCount"),
            @Mapping(source = "type.type", target = "type"),
            @Mapping(source = "maker", target = "make")
    })
    CarDto carToCarDto(Car car);
}
